/*
 Copyright (c) 2013 MeherTJ G. All rights reserved.
 License: LGPL for personnal study or free software.
 */

#pragma once

#include "zen_macro.h"
/**
 when import 'zen-app', use `ZenAppMain` as main function.
 in ZenAppMain, call Zen::App::Get()->
 */
extern int ZenAppMain(int argc, char const ** argv);

#if ! ZEN_RUNTIME_VISUAL
#	warning "zen_app can only apply to a visual system"
#else

#if ZEN_OS_APPLE_IOS
// ios : metal/gles
#	if ZEN_P_DRAW_METAL
#		define ZEN_DRAW_METAL 1
#	elif ZEN_P_DRAW_GLES
#		define ZEN_DRAW_GLES  1
#	else
#		define ZEN_DRAW_METAL 1
#	endif
#elif defined(ZEN_OS_APPLE_MAC)
// mac : metal
#	define ZEN_DRAW_METAL 1
#else
// android windows : gles
#	define ZEN_DRAW_GLES  1
#endif

// clean
#if ZEN_DRAW_METAL
#	undef ZEN_DRAW_GLES
#	define ZEN_DRAW_GLES 0
#endif

#if ZEN_DRAW_GLES
#	undef ZEN_DRAW_METAL
#	define ZEN_DRAW_METAL 0
#endif

#endif // ZEN_RUNTIME_VISUAL

#include "zen_vector.h"

namespace Zen {
	struct AppKey
	{
		int type;
		uint32_t value;
	};

	struct AppTouch
	{
		uint32_t no;
		float x, y;
	};

//	struct AppMouseState
//	{
//		uint32_t key_status;
//		float x, y;
//	};

	class AppDelegate
	{
	public:
		virtual ~AppDelegate() = default;

		/// life circle. [
		virtual void onLaunch(Zen::Size2 view_size) {}

		virtual void onResize(Zen::Size2 view_size) {}

		virtual void onPause() {}

		virtual void onResume() {}

		virtual void onUpdate() {}

		virtual void onDraw() {}

		virtual void onExit() {}

		/// life circle. ]

		/// touch event... [

		virtual void onTouchDown(AppTouch touch) {}

		virtual void onTouchMove(AppTouch touch) {}

		virtual void onTouchUp(AppTouch touch) {}

		virtual void onTouchCancel(AppTouch touch) {}

//		virtual void onMouseMove(AppMouseState mouse) {}
//
//		virtual void onMouseKeyDown(AppMouseState mouse) {}
//
//		virtual void onMouseKeyUp(AppMouseState mouse) {}

		/// touch event... ]

		/// keyboard event. [

		virtual void onKeyDown(AppKey key) {}

		virtual void onKeyUp(AppKey key) {}

		/// keyboard event. ]

		virtual void onEvent(std::string event) {}
	};
}

namespace Zen {

	class App
	{
	protected:
		App() = default;
		virtual ~App() = default;
	public:
		static App * Get();

		virtual void setRuntimeDelegate(std::shared_ptr<AppDelegate> delegate) = 0;

		virtual std::shared_ptr<AppDelegate> getRuntimeDelegate() = 0;

		virtual bool isMultiTouch() = 0;

		virtual void setMultiTouch(bool) = 0;

		virtual bool isRotatable() = 0;

		virtual void setRotatable(bool) = 0;

		virtual float getFramesPerSecond() = 0;

		virtual void  setFramesPerSecond(float) = 0;

		virtual bool isStatusVisible() = 0;

		virtual void setStatusVisible(bool) = 0;
		
		virtual bool isBGUpdate() = 0;
		
		virtual void setBGUpdate(bool) = 0;
	};
}
